import * as RecognizeServices from '../services/Recognize/recognize';

export default {
  namespace: 'recognize',
  state: {},
  reducers: {
    save(state, { payload: recognize }) {
      return { ...state, ...recognize };
    },
  },
  effects: {
    *fetchRecognize({ payload: query }, { call, put }) {
      const { data: recognize } = yield call(RecognizeServices.fetch, query);
      yield put({ type: 'save', payload: recognize });
    },
    *saveRecognize({ payload }, { call, put }) {
      const { data: recognize } = yield call(RecognizeServices.save, payload);
      yield put({ type: 'save', payload: recognize });
    },
    *updateResource({ payload }, { call, put }) {
      const { data: recognize } = yield call(RecognizeServices.updateResource, payload.cate_id, payload.resource_tag_title);
      yield put({ type: 'save', payload: recognize });
    },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      dispatch({ type: 'fetchRecognize', payload: {} });
      // return history.listen(({ pathname, query }) => {
      //   if (pathname === '/') {
      //     dispatch({ type: 'fetchRecognize', payload: query });
      //   }
      // });
    },
  },
};
